package com.company.bookstore.common.SpringUtils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Locale;

@Component
public class SpringUtil implements ApplicationContextAware   {
    private static ApplicationContext context;
    @Override
    @SuppressWarnings("static-access" )
    public void setApplicationContext(ApplicationContext context)
            throws BeansException {
        // TODO Auto-generated method stub
        this.context = context;
    }

    public static Object getBean(Class<?> clazz){
        return context.getBean(clazz);
    }

    public static String getMessage(String key){
        return context.getMessage(key, null, Locale.getDefault());
    }
}
